package com.jiuxian.scheduling.tasks;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * Created by wangjingqing on 2017/12/18.
 */
public abstract class Task implements Job {

    /**
     * 之前执行<br>
     */
    public boolean before(JobExecutionContext jobExecutionContext){return true;}

    /**
     * 之后执行<br>
     */
    public void after(JobExecutionContext jobExecutionContext){}

    /**
     * 执行<br>
     */
    public abstract  void doExecute(JobExecutionContext jobExecutionContext);

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            if(!before(jobExecutionContext)){
                return;
            }
            doExecute(jobExecutionContext);
        } finally {
            after(jobExecutionContext);
        }
    }
}
